package com.wsl.aop.dynamic;

import com.wsl.aop.pattern.RealSubject;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author ：wangshuliang
 * @date ：Created in 2019/6/5 8:05
 * @description：jdk动态代理
 * @modified By：
 */
public class JdkProxySubject implements InvocationHandler {
    public JdkProxySubject(RealSubject realSubject) {
        this.realSubject = realSubject;
    }

    private RealSubject realSubject;
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("before");
        Object result= null;
        try{
            result=method.invoke(realSubject,args);
        }catch (Exception e){
            System.out.println("e"+e.getMessage());
            throw  e;
        }finally {
            System.out.println("after");
        }
        return null;
    }
}
